<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <style>
    	.odiv{
		   display:table;
		   background:#fff;
		   width:100%;
		   padding:5px;
		   border-top:1px solid #E1E1E1; 
		   border-bottom:1px solid #E1E1E1;
	   }
	   .odiv1{
		   display:table;
		   background:#fff;
		   width:100%;
		   padding:5px;
		   border-top:1px solid #E1E1E1; 
		   border-bottom:1px solid #E1E1E1;
	   }
	   .idiv{
		   float: left;
		   font-size:15px;
		   margin-left: 10px;
		   height:40px;
		   line-height:40px;
	   }
	   .idiv1{
		   float: left;
		   font-size:15px;
		   margin-left: 10px;
		   min-height:40px;
		   line-height:40px;
	   }
	   .div_text{
		   float: right;
		   height:40px;
		   line-height:40px;
		   width:65%;
		   color: #8d8d8d;
		   font-size:15px;
		   text-align: right;
		   overflow:hidden;
		   white-space: nowrap; 
		   text-overflow: ellipsis;
		   margin-right:10px;
	   }
	    textarea:focus {
		    outline: none;
		}
	   .div_text1{
		   float: right;
		   min-height:40px;
		   width:65%;
		   color: #8d8d8d;
		   font-size:15px;
		   text-align: right;
		   overflow:hidden;
		   white-space: nowrap; 
		   text-overflow: ellipsis;
		   margin-right:10px;
	   }
	   .ipt{
	     border:none;
	     outline:none;
	     width:100%;
	     font-size:16px;
	   }
	   .div_img{
	       float: left;
	       width: 100%;
	       text-align: center;
	       height:200px;
	       line-heigth: 200px;
	    }
	   body {
	    overflow-x:hidden;
	    margin: 0;
	   }
	   html {
	    overflow-x:hidden;
	   }
    </style>
</head>
<body style="background:url(../../image/bj.png) repeat-x 0;background-size:100%;">
<div style="background:url(../../image/mainbg.png) no-repeat right 0 bottom 0%;">
<div>
	<header id="statusBar">
		<div style="width:100%;display:table;background: #fff;position:fixed;border-bottom:1px solid #EAEAEA;z-index: 9999;height: 50px;" >
			<div style="float:left;width: 20%;height: 50px;line-height: 50px;" tapmode="presshover" onclick="api.closeWin();">
			  <div style="float:left;width: 30%;height: 50px;">
			   <img style="width: 24px;margin-top: 13px;" src="../../image/blc_back.png" />
			   </div>
			   <div style="float:left;width: 50%;">
			   返回
			   </div>
			</div>
			<div style="float:left;width: 60%;height: 50px;line-height: 50px;text-align: center;font-weight:bold;">
			 进沟申请
			</div>
		</div>
	</header>
      <div style="height:70px"></div>
      <div class="odiv">
      	<div style="height:40px;line-height:40px;font-size: 15px;width: 50%;float: left;text-align: center;">
      	  <input type="radio" id="yesc" name="haveCar" onchange="haveCar(this);" checked="checked" value="true" style=""/><label for="yesc">有车</label>  
      	</div>
      	<div style="height:40px;line-height:40px;font-size: 15px;width: 50%;float: left;text-align: center;">
      	  <input type="radio" id="noc" name="haveCar" onchange="haveCar(this);" value="false" style=""/><label for="noc">无车</label>
      	</div>
      </div>
      <div class='odiv'>  
		  <div class='idiv'>进沟时间</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="date" class="ipt" id="enterDate" placeholder="请选择进沟日期"/>
		  </div>
	  </div>
	  <div class='odiv'>  
		  <div class='idiv'>出沟时间</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="date" class="ipt" id="leaveDate" placeholder="请选择出沟日期"/>
		  </div>
	  </div>
      <div class='odiv1'>  
		  <div class='idiv1'>进沟事由</div>
		  <div class="div_text1" style="margin-right:20px;">
		  <textarea id="enterReason" style="width: 100%;font-size:15px;margin-top: 5px;" onkeyup="MaxMe(this)"></textarea>
		  </div> 
	  </div>
	  
	  
      <div style="display: table;width: 100%;display: none;" id="haveNoCarDiv">
      <div class="odiv">
      	<div style="height:40px;line-height:40px;font-size: 20px;text-align: left;">
      	人员信息
      	</div>
      </div>
      <div class='odiv'>  
		  <div class='idiv'>姓名</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="text" class="ipt" id="peopleName" placeholder="请输入人员姓名"/>
		  </div>
	  </div>
	  <div class='odiv'>  
		  <div class='idiv'>身份证</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="text" class="ipt" id="peopleCard" placeholder="请输入身份证号"/>
		  </div> 
	  </div>
	  <div class='odiv'>  
		  <div class='idiv'>联系方式</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="text" class="ipt" id="peopleTelephone" placeholder="请输入联系方式"/>
		  </div> 
	  </div>
	   <div id="RyList">
	  </div>
	  
	  <div id="tjry" style="display:table;text-align:center;width:40%;height:35px;background: #32CD32;margin: 10px auto;color:#fff;line-height: 35px;border-radius:5px;" onclick="addRy()" tammode="presshover" >添加人员</div>
      </div>
      
      
      <div style="display: table;width: 100%;" id="haveCarDiv">
      
      <div class="odiv">
      	<div style="height:40px;line-height:40px;font-size: 20px;text-align: left;">
      	驾驶员信息
      	</div>
      </div>
	  <div class='odiv'>  
		  <div class='idiv'>姓名</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="text" class="ipt" id="driverName" placeholder="请输入驾驶员姓名"/>
		  </div>
	  </div>
	  <div class='odiv'>  
		  <div class='idiv'>身份证</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="text" class="ipt" id="driverCard" placeholder="请输入驾驶员身份证"/>
		  </div> 
	  </div>
	  <div class='odiv'>  
		  <div class='idiv'>车牌号</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="text" class="ipt" id="plateNum" placeholder="请输入车牌号"/>
		  </div> 
	  </div>
	  <div class='odiv'>  
		  <div class='idiv'>联系方式</div>
		  <div class="div_text" style="margin-right:20px;">
		  <input  type="text" class="ipt" id="driverTelephone" placeholder="请输入联系方式"/>
		  </div> 
	  </div>
	  
	  <div style="height:20px"></div>
	  
	  <div class="odiv">
      	<div style="text-align: center;height:40px;line-height:40px;font-size: 20px;text-align: left;">
      	乘客信息
      	</div>
      </div>
	  <div id="CkList">
	  </div>
	  
	  <div id="tjck" style="display:table;text-align:center;width:40%;height:35px;background: #32CD32;margin: 10px auto;color:#fff;line-height: 35px;border-radius:5px;" onclick="addCk()" tammode="presshover" >添加乘客</div>
	  <div id="tjzp" style="display: table;width: 100%;margin-top: 20px;">
		  <div class="div_img">
	          <div tapmode="presshover" onclick="choosePic()" style="text-align:center;width:180px;height: 180px;margin: 0 auto;vertical-align: middle;">
	             <img id="clzp" src="../../image/tabBar/clgl_mrcl.jpg" style="max-width: 180px;max-height: 180px;border-radius: 5px;"/>
	             <input type="hidden" id="pic" />
	          </div>
	          <div style="color: #8d8d8d;">车辆照片</div>
		  </div>
	  </div>
	  </div>
	  <div style="padding: 10px 0;width:100%;text-align: center;margin-top: 10px;" onclick="saveCL();" tapmode="presshover">
		<div style="width:80%;height:35px;background: #27a8fa;margin:0 auto;color:#fff;line-height: 35px;border-radius:5px;">确认保存</div>
	  </div>
	</div>
</div>	
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../resource/jquery214.js"></script>
<script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
<script type="text/javascript" src="../../script/constants.js"></script>
<script type="text/javascript">
	apiready = function(){
		api.parseTapmode();
		$api.fixStatusBar($api.dom('header'));
		if(api.systemType=="ios"){
			document.getElementById("statusBar").style.background="#298cb4";
		}
		var cltj_type = api.pageParam.cltj_type;
		if(cltj_type==1){
			$("#tjzp").hide();
		}
		var is_load = api.pageParam.is_load_ck;
		console.log(is_load);
		if(is_load==1){
			$("#tjck").hide();
			$("#tjry").hide();
			var driverName = api.pageParam.driverName;
			var driverCard = api.pageParam.driverCard;
			var plateNum = api.pageParam.plateNum;
			var driverTelephone = api.pageParam.driverTelephone;
			var passengerNames = api.pageParam.passengerNames;
			var passengerTelephones = api.pageParam.passengerTelephones;
			var passengerIdcards = api.pageParam.passengerIdcards;
			var enterDate = api.pageParam.enterDate;
			var leaveDate = api.pageParam.leaveDate;
			var enterReason = api.pageParam.enterReason;
			console.log("driverName:"+driverName);
			console.log("driverCard:"+driverCard);
			console.log("plateNum:"+plateNum);
			if(plateNum == "" || plateNum == undefined || plateNum == "undefined"){
			    document.getElementById("noc").checked = true;
			    $("#haveCarDiv").hide();
	            $("#haveNoCarDiv").show();
			    $("#enterDate").val(enterDate);
			    $("#leaveDate").val(leaveDate);
			    $("#enterReason").val(enterReason);
			    $("#peopleName").val(driverName);
			    $("#peopleCard").val(driverCard);
			    $("#peopleTelephone").val(driverTelephone);
			    $("#enterDate").attr("readonly","readonly");
			    $("#leaveDate").attr("readonly","readonly");
			    $("#enterReason").attr("readonly","readonly");
				$("#peopleName").attr("readonly","readonly");
				$("#peopleCard").attr("readonly","readonly");
				$("#peopleTelephone").attr("readonly","readonly");
				if(passengerNames!=null&&passengerNames!=""&&passengerNames!=undefined){
					var arrayName = passengerNames.split(",");
					var arrayPhone= passengerTelephones.split(",");
					var arrayIdcard = passengerIdcards.split(",");
					var CkList = document.getElementById("RyList");
					for(var i=0;i<arrayName.length;i++){
						var div = document.createElement("div");
						div.innerHTML="<div style='border-top:2px solid #555555;border-bottom:2px solid #555555;margin-top:5px;'> "+
									  " <div class='odiv'> "+
									  " <div class='idiv'>姓名</div> "+
						  			  " <div class='div_text' style='margin-right:20px;'> "+
						  			  " <input  type='text' class='ipt' name='personName' value='"+arrayName[i]+"' placeholder='请输入姓名'/> "+
						  			  " </div> "+
					  				  " </div> "+
					  				  " <div  class='odiv'> "+
									  " <div class='idiv'>联系方式</div> "+
						  			  " <div class='div_text' style='margin-right:20px;'> "+
						  			  " <input  type='text' class='ipt' name='personTelephone' value='"+arrayPhone[i]+"' placeholder='请输入联系方式'/> "+
						  			  " </div> "+
					  				  " </div> "+
					  				  " <div  class='odiv'> "+
									  " <div class='idiv'>身份证号</div> "+
						  			  " <div class='div_text' style='margin-right:20px;'> "+
						  			  " <input  type='text' class='ipt' name='personIdcard' value='"+arrayIdcard[i]+"' placeholder='请输入身份证号'/> "+
						  			  " </div> "+
					  				  " </div> "+
					  				  //" <div style='text-align:center;width:40%;height:35px;background: #CD3700;margin: 10px auto;color:#fff;line-height: 35px;border-radius:5px;' onclick='$(this).parent().remove();' >删除乘客</div> "+
					  				  " </div> ";
						CkList.appendChild(div);
					}
					$("input[name='personName']").attr("readonly","readonly");
					$("input[name='personTelephone']").attr("readonly","readonly");
					$("input[name='personIdcard']").attr("readonly","readonly");
				}
			}else{
			    document.getElementById("yesc").checked = true;
			    $("#haveCarDiv").show();
	            $("#haveNoCarDiv").hide();
			    $("#enterDate").val(enterDate);
			    $("#leaveDate").val(leaveDate);
			    $("#enterReason").val(enterReason);
			    $("#driverName").val(driverName);
			    $("#driverCard").val(driverCard);
			    $("#plateNum").val(plateNum);
			    $("#driverTelephone").val(driverTelephone);
			    $("#enterDate").attr("readonly","readonly");
			    $("#leaveDate").attr("readonly","readonly");
			    $("#enterReason").attr("readonly","readonly");
				$("#driverName").attr("readonly","readonly");
				$("#driverCard").attr("readonly","readonly");
				$("#plateNum").attr("readonly","readonly");
				$("#driverTelephone").attr("readonly","readonly");
				if(passengerNames!=null&&passengerNames!=""&&passengerNames!=undefined){
					var arrayName = passengerNames.split(",");
					var arrayPhone= passengerTelephones.split(",");
					var arrayIdcard = passengerIdcards.split(",");
					var CkList = document.getElementById("CkList");
					for(var i=0;i<arrayName.length;i++){
						var div = document.createElement("div");
						div.innerHTML="<div style='border-top:2px solid #555555;border-bottom:2px solid #555555;margin-top:5px;'> "+
									  " <div class='odiv'> "+
									  " <div class='idiv'>姓名</div> "+
						  			  " <div class='div_text' style='margin-right:20px;'> "+
						  			  " <input  type='text' class='ipt' name='passengerName' value='"+arrayName[i]+"' placeholder='请输入乘客姓名'/> "+
						  			  " </div> "+
					  				  " </div> "+
					  				  " <div  class='odiv'> "+
									  " <div class='idiv'>联系方式</div> "+
						  			  " <div class='div_text' style='margin-right:20px;'> "+
						  			  " <input  type='text' class='ipt' name='passengerTelephone' value='"+arrayPhone[i]+"' placeholder='请输入乘客联系方式'/> "+
						  			  " </div> "+
					  				  " </div> "+
					  				  " <div  class='odiv'> "+
									  " <div class='idiv'>身份证号</div> "+
						  			  " <div class='div_text' style='margin-right:20px;'> "+
						  			  " <input  type='text' class='ipt' name='passengerIdcard' value='"+arrayIdcard[i]+"' placeholder='请输入乘客联系方式'/> "+
						  			  " </div> "+
					  				  " </div> "+
					  				  //" <div style='text-align:center;width:40%;height:35px;background: #CD3700;margin: 10px auto;color:#fff;line-height: 35px;border-radius:5px;' onclick='$(this).parent().remove();' >删除乘客</div> "+
					  				  " </div> ";
						CkList.appendChild(div);
					}
					$("input[name='passengerName']").attr("readonly","readonly");
					$("input[name='passengerTelephone']").attr("readonly","readonly");
					$("input[name='passengerIdcard']").attr("readonly","readonly");
				}
			}
		}
	};
	
	function haveCar(){
	    var haveCar = $('input[name="haveCar"]:checked').val();
	    if(haveCar == "false"){
	       $("#haveCarDiv").hide();
	       $("#haveNoCarDiv").show();
	    }else{
	       $("#haveCarDiv").show();
	       $("#haveNoCarDiv").hide();
	    }
	}
	
	function choosePic(i){
		api.confirm({
    		title: '选择图片获取方式',
    		msg: ' ',
    		buttons: ['相机', '图册']
		}, function(ret, err) {
    		var index = ret.buttonIndex;
    		if(index=="1"){
    			api.getPicture({
    				sourceType:'camera',
    				encodingType:'jpg',
    				quality:100,
    				targetWidth: 600,
    				targetHeight: 600,
    				destinationType:'base64'
                },function(ret,err){
                	if(ret){
	                	if(ret.data.length>0){
	                		document.getElementById("clzp").src = ret.base64Data;   
            				$("#pic").val(ret.data); 
	                	}
                		
                	}
                });
    		}else if(index=="2"){
    			api.getPicture({
    				sourceType:'library',
    				encodingType:'jpg',
    				quality:100,
    				targetWidth: 600,
    				targetHeight: 600,
    				destinationType:'base64'
                },function(ret,err){
	                if(ret){
	                	if(ret.data.length>0){
	                		document.getElementById("clzp").src = ret.base64Data; 
            				$("#pic").val(ret.data);
	                	}
	                }
                });
    		}
		});
	}
	
	function toindex(){
		api.closeWin();
	}
	
	function addRy(){
		var RyList = document.getElementById("RyList");
		var div = document.createElement("div");
		
		div.innerHTML="<div style='border-top:2px solid #555555;border-bottom:2px solid #555555;margin-top:5px;'> "+
					  " <div class='odiv'> "+
					  " <div class='idiv'>姓名</div> "+
		  			  " <div class='div_text' style='margin-right:20px;'> "+
		  			  " <input  type='text' class='ipt' name='personName' placeholder='请输入人员姓名'/> "+
		  			  " </div> "+
	  				  " </div> "+
	  				  " <div  class='odiv'> "+
					  " <div class='idiv'>身份证号</div> "+
		  			  " <div class='div_text' style='margin-right:20px;'> "+
		  			  " <input  type='text' class='ipt' name='personIdcard' placeholder='请输入身份证号'/> "+
		  			  " </div> "+
	  				  " </div> "+
	  				  " <div  class='odiv'> "+
					  " <div class='idiv'>联系方式</div> "+
		  			  " <div class='div_text' style='margin-right:20px;'> "+
		  			  " <input  type='text' class='ipt' name='personTelephone' placeholder='请输入联系方式'/> "+
		  			  " </div> "+
	  				  " </div> "+
	  				  " <div style='text-align:center;width:40%;height:35px;background: #CD3700;margin: 10px auto;color:#fff;line-height: 35px;border-radius:5px;' onclick='$(this).parent().remove();' >删除人员</div> "+
	  				  " </div> ";
		RyList.appendChild(div);
	}
	
	function addCk(){
		var CkList = document.getElementById("CkList");
		var div = document.createElement("div");
		
		div.innerHTML="<div style='border-top:2px solid #555555;border-bottom:2px solid #555555;margin-top:5px;'> "+
					  " <div class='odiv'> "+
					  " <div class='idiv'>姓名</div> "+
		  			  " <div class='div_text' style='margin-right:20px;'> "+
		  			  " <input  type='text' class='ipt' name='passengerName' placeholder='请输入乘客姓名'/> "+
		  			  " </div> "+
	  				  " </div> "+
	  				  " <div  class='odiv'> "+
					  " <div class='idiv'>身份证号</div> "+
		  			  " <div class='div_text' style='margin-right:20px;'> "+
		  			  " <input  type='text' class='ipt' name='passengerIdcard' placeholder='请输入乘客身份证号'/> "+
		  			  " </div> "+
	  				  " </div> "+
	  				  " <div  class='odiv'> "+
					  " <div class='idiv'>联系方式</div> "+
		  			  " <div class='div_text' style='margin-right:20px;'> "+
		  			  " <input  type='text' class='ipt' name='passengerTelephone' placeholder='请输入乘客联系方式'/> "+
		  			  " </div> "+
	  				  " </div> "+
	  				  " <div style='text-align:center;width:40%;height:35px;background: #CD3700;margin: 10px auto;color:#fff;line-height: 35px;border-radius:5px;' onclick='$(this).parent().remove();' >删除乘客</div> "+
	  				  " </div> ";
		CkList.appendChild(div);
	}
	
	function saveCL(){
		var dl_phone = $api.getStorage("dl_phone");
		if (typeof(dl_phone) == "undefined" || dl_phone == "undefined" || dl_phone == "" || dl_phone == null) {
		   api.alert({
				msg: '登录已过期，请重新登录！'
			}, function(ret, err) {
				api.openWin({
					name: '跳转登陆',
					url: '../login.html'
				});
			});
		}else{
		    var enterDate = $("#enterDate").val();
		    var leaveDate = $("#leaveDate").val();
		    var enterReason = $("#enterReason").val();
		    if(enterDate == "" || leaveDate == ""){
		       api.alert({msg: "请选择进出沟日期"});
		       return;
		    }
		    if(enterReason == ""){
		       api.alert({msg: "请输入进沟事由"});
		       return;
		    } 
		    var haveCar = $('input[name="haveCar"]:checked').val();
		    if(haveCar == "false"){
		    	var driverName = $("#peopleName").val();
				if(driverName==null||driverName==""||driverName==undefined){
					api.alert({msg:"请输入姓名！"});
					return;
				}
				var driverCard = $("#peopleCard").val();
				if(driverCard==null||driverCard==""||driverCard==undefined){
					api.alert({msg:"请输入身份证号！"});
					return;
				}
				var driverTelephone = $("#peopleTelephone").val();
				if(driverTelephone==null||driverTelephone==""||driverTelephone==undefined){
					api.alert({msg:"请输入联系方式！"});
					return;
				}
				var passengerNames ="";
				var passengerIdcards = "";
				var num = 0;
				var count =0;
				var flag=true;
				$("input[name='personName']").each(function(){
					var passengerName = $(this).val();
					if(passengerName==null||passengerName==""||passengerName==undefined){
						flag=false;
						api.alert({msg:"人员姓名不能为空！"});
						return false;//each返回false只能提前终止循环，不能终止程序向下执行
					}else{
						if(count==0){
							passengerNames = passengerNames+passengerName;
							count++;
						}else{
							passengerNames = passengerNames+","+passengerName;
						}
					}
				});
				$("input[name='personIdcard']").each(function(){
					var passengerIdcard = $(this).val();
					if(passengerIdcard==null||passengerIdcard==""||passengerIdcard=="undefined"){
						flag=false;
						api.alert({msg:"身份证号不能为空！"});
						return false;//each返回false只能提前终止循环，不能终止程序向下执行
					}else{
						if(num==0){
							passengerIdcards = passengerIdcards+passengerIdcard;
							num++;
						}else{
							passengerIdcards = passengerIdcards+","+passengerIdcard;
						}
					}
				});
				if(flag){
					var passengerTelephones = $("input[name='personTelephone']").map(function(){if($(this).val()==null||$(this).val()==""||$(this).val()==undefined){ return " ";}else{return $(this).val();}}).get().join(",");
					var uiId;
					var UILoading = api.require('UILoading');
					UILoading.flower({
			            center: {
				            x: api.winWidth/2.0,
				            y: api.winHeight/2.0
			            },
			            size: 30,
			            fixed: true,
			            mask: "rgba(0,0,0,0.5)"
		            },function(ret,err){
		            	uiId = ret.id;
		            });
		            var callback = function(ret,err){
		            	UILoading.closeFlower({
			                id: uiId
		                });
		                if(ret){
		                	if(ret.success){
		                		//api.alert({msg: "保存成功！"});
					           	api.sendEvent({
					                 name:'addCk'
				                });
				                api.closeWin();
		                	}else{
		                		api.alert({msg: "保存失败！原因："+ret.msg});
		                	}
		                }else{
		                	api.alert({msg:"保存失败，原因："+err.msg});
		            	}
					};
					var path;
					//cltj_type 0 为管理人员添加 1为普通车主添加
					var cltj_type = api.pageParam.cltj_type;
					var clzp="";
					if(cltj_type==0){
						clzp = $("#clzp").attr("src");
						path = url.saveSceneryInfo;
					}else{
						path = url.saveDriverInfo;
					}
					var content = {"dl_phone":dl_phone,"driverName":driverName,"driverCard":driverCard,"plateNum":"","driverTelephone":driverTelephone,
					"passengerNames":passengerNames,"passengerIdcards":passengerIdcards,"passengerTelephones":passengerTelephones,"clzp":clzp,"enterDate":enterDate,"leaveDate":leaveDate,"enterReason":enterReason};
					apiAjax(JSON.stringify(content),path,callback);
				}
		    }else{
				var driverName = $("#driverName").val();
				if(driverName==null||driverName==""||driverName==undefined){
					api.alert({msg:"请输入驾驶员姓名！"});
					return;
				}
				var driverCard = $("#driverCard").val();
				if(driverCard==null||driverCard==""||driverCard==undefined){
					api.alert({msg:"请输入驾驶员身份证！"});
					return;
				}
				var plateNum = $("#plateNum").val();
				if(plateNum==null||plateNum==""||plateNum==undefined){
					api.alert({msg:"请输入车牌号！"});
					return;
				}
				var driverTelephone = $("#driverTelephone").val();
				if(driverTelephone==null||driverTelephone==""||driverTelephone==undefined){
					api.alert({msg:"请输入驾驶员联系方式！"});
					return;
				}
				var passengerNames ="";
				var passengerIdcards = "";
				var num = 0;
				var count =0;
				var flag=true;
				$("input[name='passengerName']").each(function(){
					var passengerName = $(this).val();
					if(passengerName==null||passengerName==""||passengerName==undefined){
						flag=false;
						api.alert({msg:"乘客姓名不能为空！"});
						return false;//each返回false只能提前终止循环，不能终止程序向下执行
					}else{
						if(count==0){
							passengerNames = passengerNames+passengerName;
							count++;
						}else{
							passengerNames = passengerNames+","+passengerName;
						}
					}
				});
				$("input[name='passengerIdcard']").each(function(){
					var passengerIdcard = $(this).val();
					if(passengerIdcard==null||passengerIdcard==""||passengerIdcard=="undefined"){
						flag=false;
						api.alert({msg:"乘客身份证号不能为空！"});
						return false;//each返回false只能提前终止循环，不能终止程序向下执行
					}else{
						if(num==0){
							passengerIdcards = passengerIdcards+passengerIdcard;
							num++;
						}else{
							passengerIdcards = passengerIdcards+","+passengerIdcard;
						}
					}
				});
				if(flag){
					var passengerTelephones = $("input[name='passengerTelephone']").map(function(){if($(this).val()==null||$(this).val()==""||$(this).val()==undefined){ return " ";}else{return $(this).val();}}).get().join(",");
					var uiId;
					var UILoading = api.require('UILoading');
					UILoading.flower({
			            center: {
				            x: api.winWidth/2.0,
				            y: api.winHeight/2.0
			            },
			            size: 30,
			            fixed: true,
			            mask: "rgba(0,0,0,0.5)"
		            },function(ret,err){
		            	uiId = ret.id;
		            });
		            var callback = function(ret,err){
		            	UILoading.closeFlower({
			                id: uiId
		                });
		                if(ret){
		                	if(ret.success){
		                		//api.alert({msg: "保存成功！"});
					           	api.sendEvent({
					                 name:'addCk'
				                });
				                api.closeWin();
		                	}else{
		                		api.alert({msg: "保存失败！原因："+ret.msg});
		                	}
		                }else{
		                	api.alert({msg:"保存失败，原因："+err.msg});
		            	}
					};
					var path;
					//cltj_type 0 为管理人员添加 1为普通车主添加
					var cltj_type = api.pageParam.cltj_type;
					var clzp="";
					if(cltj_type==0){
						clzp = $("#clzp").attr("src");
						path = url.saveSceneryInfo;
					}else{
						path = url.saveDriverInfo;
					}
					var content = {"dl_phone":dl_phone,"driverName":driverName,"driverCard":driverCard,"plateNum":plateNum,"driverTelephone":driverTelephone,
					"passengerNames":passengerNames,"passengerIdcards":passengerIdcards,"passengerTelephones":passengerTelephones,"clzp":clzp,"enterDate":enterDate,"leaveDate":leaveDate,"enterReason":enterReason};
					apiAjax(JSON.stringify(content),path,callback);
				}
			}
		}
	}
	
	function MaxMe(o) {     
      if (window.navigator.userAgent.indexOf("Firefox") > -1) {
        o.style.height = o.scrollTop + o.scrollHeight + "px";
      }
      else {
        if (o.scrollTop > 0) o.style.height = o.scrollTop + o.scrollHeight + "px";
      }
    }
</script>
</html>